package com.lovely3x.loginandresgiter;

import android.os.Parcel;
import android.os.Parcelable;

import com.litesuits.orm.db.annotation.Column;
import com.litesuits.orm.db.annotation.Mapping;
import com.litesuits.orm.db.annotation.PrimaryKey;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.enums.AssignType;
import com.litesuits.orm.db.enums.Relation;
import com.lovely3x.common.managements.user.IUser;
import com.lovely3x.common.managements.user.IUserPreferences;
import com.lovely3x.common.utils.PoJoCopier;
import com.lovely3x.loginandresgiter.bean.SimpleUserPreferences;

/**
 * user的简易实现
 * Created by lovely3x on 16-4-15.
 */
@Table(SimpleUser.TABLE_NAME)
public class SimpleUser implements IUser, Parcelable {

    public static final int MAN = 1;

    public static final int WOMAN = 2;

    public static final int OTHER = 0;

    /**
     * 表名
     */
    public static final String TABLE_NAME = "tab_user";

    @Column("user_state")
    private int mUserState = STATE_OFFLINE;

    @Column("token")
    private String token;

    /**
     * 电话号码
     */
    @Column("phone")
    @PrimaryKey(AssignType.BY_MYSELF)
    private long phone;
    /**
     * 密码
     */
    private String password;

    /**
     * MD5 密码
     */
    @Column("md5_password")
    private String MD5Password;

    /**
     * 生日
     */
    @Column("birthday")
    private String birthday;
    /**
     * 性别
     */
    @Column("sex")
    private int sex;
    /**
     * 昵称
     */
    @Column("nickname")
    private String nickname;
    /**
     * 头像地址
     */
    @Column("headaddress")
    private String headaddress;
    /**
     * 年龄
     */
    @Column("age")
    private int age;
    /**
     * 环信的用户名
     */
    @Column("easemob_user_name")
    private String easemobUsername;

    /**
     * 签名
     */
    @Column("user_information")
    private String userInformation;

    /**
     * 邀请码
     */
    @Column("invite_code")
    private String inviteCode;

    /**
     * 用户名
     */
    @Column("user_name")
    private String userName;

    /**
     * 用户偏好设置
     */
    @Mapping(Relation.OneToOne)
    private SimpleUserPreferences preference = new SimpleUserPreferences();
    /**
     * 体重
     */
    @Column("_weight")
    private float weight;
    /**
     * 身高
     */
    @Column("_height")
    private float height;

    /**
     * 用户id
     */
    @Column("_uid")
    private String uid;

    @Column("_last_login_time")
    private long lastLoginTime;

    /**
     * 用户的类型
     */
    @PoJoCopier.Ignore
    @Column("_type")
    private int type = -1;

    @Column("_profession")
    private String profession;

    @Column("_divisionname")
    private String divisionname;

    @Column("_jobtitle")
    private String jobtitle;

    @Column("_sparemoney")
    private float sparemoney;

    @Column("_usergrade")
    private float usergrade;

    @Column("_name")
    private String name;

    @Column("_isvip")
    private boolean isvip;

    //（-1：未认证  0：认证中   1：成功   2：失败）
    @Column("_isauth")
    private int isauth;

    @Column("_hospital")
    private String hospital;

    @Column("_ispaypwd")
    private boolean ispaypwd;

    /**
     * 是否绑定手机
     */
    @Column("_isphone")
    private boolean isphone;


    public SimpleUser() {
    }

    public SimpleUser(int mUserState, String token, long phone, String password, String MD5Password, String birthday, int sex, String nickname, String headaddress, int age, String easemobUsername, String userInformation, String inviteCode, String userName, SimpleUserPreferences preference, float weight, float height, String uid, long lastLoginTime, int type, String profession, String divisionname, String jobtitle, float sparemoney, float usergrade, String name, boolean isvip, int isauth, String hospital, boolean ispaypwd, boolean isphone) {
        this.mUserState = mUserState;
        this.token = token;
        this.phone = phone;
        this.password = password;
        this.MD5Password = MD5Password;
        this.birthday = birthday;
        this.sex = sex;
        this.nickname = nickname;
        this.headaddress = headaddress;
        this.age = age;
        this.easemobUsername = easemobUsername;
        this.userInformation = userInformation;
        this.inviteCode = inviteCode;
        this.userName = userName;
        this.preference = preference;
        this.weight = weight;
        this.height = height;
        this.uid = uid;
        this.lastLoginTime = lastLoginTime;
        this.type = type;
        this.profession = profession;
        this.divisionname = divisionname;
        this.jobtitle = jobtitle;
        this.sparemoney = sparemoney;
        this.usergrade = usergrade;
        this.name = name;
        this.isvip = isvip;
        this.isauth = isauth;
        this.hospital = hospital;
        this.ispaypwd = ispaypwd;
        this.isphone = isphone;
    }

    protected SimpleUser(Parcel in) {
        mUserState = in.readInt();
        token = in.readString();
        phone = in.readLong();
        password = in.readString();
        MD5Password = in.readString();
        birthday = in.readString();
        sex = in.readInt();
        nickname = in.readString();
        headaddress = in.readString();
        age = in.readInt();
        easemobUsername = in.readString();
        userInformation = in.readString();
        inviteCode = in.readString();
        userName = in.readString();
        preference = in.readParcelable(SimpleUserPreferences.class.getClassLoader());
        weight = in.readFloat();
        height = in.readFloat();
        uid = in.readString();
        lastLoginTime = in.readLong();
        type = in.readInt();
        profession = in.readString();
        divisionname = in.readString();
        jobtitle = in.readString();
        sparemoney = in.readFloat();
        usergrade = in.readFloat();
        name = in.readString();
        isvip = in.readByte() != 0;
        isauth = in.readInt();
        hospital = in.readString();
        ispaypwd = in.readByte() != 0;
        isphone = in.readByte() != 0;
    }

    public static final Creator<SimpleUser> CREATOR = new Creator<SimpleUser>() {
        @Override
        public SimpleUser createFromParcel(Parcel in) {
            return new SimpleUser(in);
        }

        @Override
        public SimpleUser[] newArray(int size) {
            return new SimpleUser[size];
        }
    };

    public static int getMAN() {
        return MAN;
    }

    public static int getWOMAN() {
        return WOMAN;
    }

    public static int getOTHER() {
        return OTHER;
    }

    public static String getTableName() {
        return TABLE_NAME;
    }

    public int getmUserState() {
        return mUserState;
    }

    public void setmUserState(int mUserState) {
        this.mUserState = mUserState;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public long getPhone() {
        return phone;
    }

    public void setPhone(long phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMD5Password() {
        return MD5Password;
    }

    public void setMD5Password(String MD5Password) {
        this.MD5Password = MD5Password;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getHeadaddress() {
        return headaddress;
    }

    public void setHeadaddress(String headaddress) {
        this.headaddress = headaddress;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getEasemobUsername() {
        return easemobUsername;
    }

    public void setEasemobUsername(String easemobUsername) {
        this.easemobUsername = easemobUsername;
    }

    public String getUserInformation() {
        return userInformation;
    }

    public void setUserInformation(String userInformation) {
        this.userInformation = userInformation;
    }

    public String getInviteCode() {
        return inviteCode;
    }

    public void setInviteCode(String inviteCode) {
        this.inviteCode = inviteCode;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public SimpleUserPreferences getPreference() {
        return preference;
    }

    public void setPreference(SimpleUserPreferences preference) {
        this.preference = preference;
    }

    public float getWeight() {
        return weight;
    }

    public void setWeight(float weight) {
        this.weight = weight;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public long getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(long lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public String getDivisionname() {
        return divisionname;
    }

    public void setDivisionname(String divisionname) {
        this.divisionname = divisionname;
    }

    public String getJobtitle() {
        return jobtitle;
    }

    public void setJobtitle(String jobtitle) {
        this.jobtitle = jobtitle;
    }

    public float getSparemoney() {
        return sparemoney;
    }

    public void setSparemoney(float sparemoney) {
        this.sparemoney = sparemoney;
    }

    public float getUsergrade() {
        return usergrade;
    }

    public void setUsergrade(float usergrade) {
        this.usergrade = usergrade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isvip() {
        return isvip;
    }

    public void setIsvip(boolean isvip) {
        this.isvip = isvip;
    }

    public int getIsauth() {
        return isauth;
    }

    public void setIsauth(int isauth) {
        this.isauth = isauth;
    }

    public String getHospital() {
        return hospital;
    }

    public void setHospital(String hospital) {
        this.hospital = hospital;
    }

    public boolean ispaypwd() {
        return ispaypwd;
    }

    public void setIspaypwd(boolean ispaypwd) {
        this.ispaypwd = ispaypwd;
    }

    public boolean isphone() {
        return isphone;
    }

    public void setIsphone(boolean isphone) {
        this.isphone = isphone;
    }

    @Override
    public String toString() {
        return "SimpleUser{" +
                "mUserState=" + mUserState +
                ", token='" + token + '\'' +
                ", phone=" + phone +
                ", password='" + password + '\'' +
                ", MD5Password='" + MD5Password + '\'' +
                ", birthday='" + birthday + '\'' +
                ", sex=" + sex +
                ", nickname='" + nickname + '\'' +
                ", headaddress='" + headaddress + '\'' +
                ", age=" + age +
                ", easemobUsername='" + easemobUsername + '\'' +
                ", userInformation='" + userInformation + '\'' +
                ", inviteCode='" + inviteCode + '\'' +
                ", userName='" + userName + '\'' +
                ", preference=" + preference +
                ", weight=" + weight +
                ", height=" + height +
                ", uid='" + uid + '\'' +
                ", lastLoginTime=" + lastLoginTime +
                ", type=" + type +
                ", profession='" + profession + '\'' +
                ", divisionname='" + divisionname + '\'' +
                ", jobtitle='" + jobtitle + '\'' +
                ", sparemoney=" + sparemoney +
                ", usergrade=" + usergrade +
                ", name='" + name + '\'' +
                ", isvip=" + isvip +
                ", isauth=" + isauth +
                ", hospital='" + hospital + '\'' +
                ", ispaypwd=" + ispaypwd +
                ", isphone=" + isphone +
                '}';
    }

    @Override
    public void setState(int state) {

    }

    @Override
    public int getState() {
        return 0;
    }

    @Override
    public IUser clone() {
        return null;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mUserState);
        dest.writeString(token);
        dest.writeLong(phone);
        dest.writeString(password);
        dest.writeString(MD5Password);
        dest.writeString(birthday);
        dest.writeInt(sex);
        dest.writeString(nickname);
        dest.writeString(headaddress);
        dest.writeInt(age);
        dest.writeString(easemobUsername);
        dest.writeString(userInformation);
        dest.writeString(inviteCode);
        dest.writeString(userName);
        dest.writeParcelable(preference, flags);
        dest.writeFloat(weight);
        dest.writeFloat(height);
        dest.writeString(uid);
        dest.writeLong(lastLoginTime);
        dest.writeInt(type);
        dest.writeString(profession);
        dest.writeString(divisionname);
        dest.writeString(jobtitle);
        dest.writeFloat(sparemoney);
        dest.writeFloat(usergrade);
        dest.writeString(name);
        dest.writeByte((byte) (isvip ? 1 : 0));
        dest.writeInt(isauth);
        dest.writeString(hospital);
        dest.writeByte((byte) (ispaypwd ? 1 : 0));
        dest.writeByte((byte) (isphone ? 1 : 0));
    }
}
